webp-animation
A high-level Rust wrapper for decoding and encoding WebP animations
See examples/encode_animation.rs
for source code of encoding the above image - example converted to gif for all-browser support, see the example.webp file
Underlying WebP format processing is handled by C-based libwebp library, which is interfaced through Rust libwebp-sys2 crate.
Functional Goals:
- Easy-to-use API that looks like Rust
- Enable decoding and encoding of WebP streams
- All configuration flags provided by
libwebp
should be usable
Non-functional Goals:
- High performance (approach
libwebp
performance without large overhead) - Write compherensive test cases, and test by automation
- Ensure safety (no memory leaks or UB). Fuzz the API's. Safe to use for end users
Non-goals
- Provide other WebP/libwebp -related functionality (such as image en/decoding or muxing). For this functionality, see e.g. libwebp-image or webp
Examples
Decoding
Will take a webp buffer, and try to decode it to frame(s)
use *;
let buffer = read.unwrap;
let decoder = new.unwrap;
for frame in decoder.into_iter
It is also possible to supply more decoding options through Decoder::new_with_options
.
Encoding
Will take n
frames as an input. WebP binary data is output at the end
(wrapped into WebPData
which acts as a &[u8]
)
use *;
// setup
let dimensions = ;
let bright_frame = .repeat;
let dark_frame = .repeat;
// init encoder. uses by default lossless encoding,
// for other alternatives see documentation about
// `new_with_options`
let mut encoder = new.unwrap;
// insert frames to specific (increasing) timestamps
for i in 0..5
// get encoded webp data
let final_timestamp = 1_000;
let webp_data = encoder.finalize.unwrap;
write.unwrap;
See docs for other encoding options, e.g. for lossy encoding.
Rust Version Support
The minimum supported Rust version is 1.47
Future plans
Keep up with upstream libwebp
changes.
Possibly provide a compherensive CLI for working with WebP animations in future (conversions, optimizations, etc.)
License
Licensed under either of
- Apache License, Version 2.0 or
- MIT license
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the software by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.